package client;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Scanner;

public class DutyFreeClient extends Client {
	ArrayList<DutyFree> dutyFreeoffers = null;
	//private Service service;
	public DutyFreeClient(Service s) {
		super(s);
	}

	public ArrayList<DutyFree> getDFList() {
		try {
			Service t = getServer();
			Socket socket = new Socket(t.getIpAddress(), t.getPort());
			PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
			out.println("getDUTYFREEList,");
			out.flush();
			BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
			String input = in.readLine();
			//System.out.println(input);
			Scanner inputScanner = new Scanner(input);
			inputScanner.useDelimiter(",");
			String returnName = inputScanner.next();
			//System.out.println(returnName);
			int noOffices = inputScanner.nextInt();
			dutyFreeoffers = new ArrayList<DutyFree>();
			//office1-ref, office1-name, office1-location, office1-phone, office1-email,
			for(int i = 0; i < noOffices; i++){
				DutyFree df = new DutyFree(inputScanner.nextInt(),inputScanner.next(),inputScanner.next(),inputScanner.next(),inputScanner.next());
				dutyFreeoffers.add(df);
			}
			out.close();
			in.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return dutyFreeoffers;
	}
}
